package _021_10_6

import "sort"

type pair struct {
	Beg int
	End int
}
type PairSlice []pair

func (this PairSlice) Less(i, j int) bool {
	if this[i].Beg > this[j].Beg {
		return true
	}
	return false
}

func (this PairSlice) Len() int {
	return len(this)
}

func (this PairSlice) Swap(i, j int) {
	temp := this[i]
	this[i] = this[j]
	this[j] = temp
}

func minmumNumberOfHost(n int, startEnd [][]int) int {
	// write code here
	var data PairSlice
	maxLen := 0
	for i := 0; i < len(startEnd); i++ {
		data = append(data, pair{Beg: startEnd[i][0], End: startEnd[i][1]})
	}
	sort.Sort(data)
	for i := 0; i < len(data)-1; i++ {
		if data[i].End > data[i+1].Beg {
			maxLen++
		}
	}
	return maxLen
}
